package com.shang.yielddemo

/**
  * Created by shangyanshuo048 on 2017/6/21.
  */
object YieldDemo {

  private val files = (new java.io.File("./src/com/shang/yielddemo")).listFiles

  private def fileLines(file: java.io.File) =
    scala.io.Source.fromFile(file).getLines.toList

  def main(args: Array[String]): Unit = {

//    println(files.size)
//    for(file <- files){
//      println(file.getName)
//    }

    val lineLengths =
      for {
        file <- files
        if file.getName.endsWith(".txt")

        line <- fileLines(file)
        trimmedLine = line.trim
        if trimmedLine.matches(".*棒.*")
      } yield line + "：合计" + trimmedLine.length + "个字。"

    // print
    lineLengths.foreach(println)
  }
}
